package com.tanhua.manager.listeners;

import com.tanhua.domain.db.Log;
import com.tanhua.manager.service.LogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(topic = "tanhua154-logs",consumerGroup = "logsGroup")
public class LogsListener implements RocketMQListener<Map> {

    @Autowired
    private LogService logService;

    @Override
    public void onMessage(Map map) {
        Long userId = Long.parseLong(map.get("userId").toString()) ; //当时放的是一个Long 但是接受时只能用Integer
        String type = (String) map.get("type");
        String logTime = (String) map.get("logTime");

        Log log = new Log();
        log.setUserId(userId);
        log.setLogTime(logTime);
        log.setPlace("北京");
        log.setEquipment("huawei meta 40");
        log.setType(type);

        logService.save(log);
        System.out.println("消息消费者已执行成功。。。。tanhua154-logs");
    }
}
